package com.guo.pet_store.controller;

import com.guo.pet_store.admin.pojo.Order;
import com.guo.pet_store.admin.pojo.Pet;
import com.guo.pet_store.admin.pojo.User;
import com.guo.pet_store.admin.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class OrderController {

    @Autowired
    OrderService orderService;

    //    更具用户id查询所有的订单
    @GetMapping("/orders")
    public String getOrder(Model model, HttpSession session, RedirectAttributes redirectAttributes){
        User user = (User)session.getAttribute("user");
        if (user ==null){
            redirectAttributes.addFlashAttribute("message","登陆后才能查看自己的购物车哦");
            return "login";
        }else{
            Long userId = user.getId();
            model.addAttribute("orders",orderService.getOrder(userId));
            return "orders";
        }

    }
}
